/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package beans;

import database.DBController;
import domain.Paper;
import java.sql.SQLException;
import java.util.List;
import javax.faces.model.SelectItem;

/**
 *
 * @author yusufu
 */

public class WriterBean {
    
    DBController dbc = new DBController();

    protected Paper p = new Paper();
    protected int paperLocalID=3;
    
    public Paper getP() {
        return p;
    }

    public void setP(Paper p) {
        this.p = p;
    }
    
    public List<SelectItem> getPlaces() throws SQLException 
    {
        dbc = new DBController();
        return dbc.getPapers();
    }
    
    public String saveNewPaper() throws Exception
    {
        dbc = new DBController();
        dbc.increasePaperCounter();
        paperLocalID=dbc.getPaperCounter();
        
        p.setWriter_ID(paperLocalID);
        dbc.savePaper(this.p);
        return "true";
    }
}
